package com.tongchengsoft.server.impl;

import java.util.HashMap;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.tongchengsoft.bean.BeanDepartmentTable;
import com.tongchengsoft.dao.IDepartmentTableDao;
import com.tongchengsoft.server.IDepartmentTableService;
import com.tongchengsoft.tools.StringTools;

/**
 * 部门 service impl
 * @author Wang
 *
 */
@Service
public class DepartmentTableServiceImpl implements IDepartmentTableService {

	@Autowired
	private IDepartmentTableDao departmentTableDao;
	
	@Override
	public boolean add(BeanDepartmentTable departmentTable) throws Exception {

		if(null == departmentTable)
			
			return false;
		if(StringTools.isEmpty(departmentTable.getBmMc()))
			
			return false;
		departmentTable.setIsDelete(0);
		Integer resultId = departmentTableDao.add(departmentTable);
		System.out.println("reusltId" + resultId);
		if(0 < resultId)
			
			return true;
		else
			
			return false;
	}

	@Override
	public boolean delete(BeanDepartmentTable departmentTable) throws Exception {

		if(null == departmentTable)
			
			return false;
		if(null == departmentTable.getLsId() || 0 == departmentTable.getLsId())
		
			return false;
		
		HashMap<String, Object> hm = new HashMap<String,Object>();
		hm.put("lsId", departmentTable.getLsId());
		if(0 < departmentTableDao.delete(hm))
			
			return true;
		else
			
			return false;
	}

	@Override
	public boolean update(BeanDepartmentTable departmentTable) throws Exception {
		
		if(null == departmentTable)
			
			return false;
		if(null == departmentTable.getLsId() || 0 == departmentTable.getLsId())
			
			return false;
		if(StringTools.isEmpty(departmentTable.getBmMc()))
			
			return false;
		HashMap<String, Object> hm = new HashMap<String, Object>();
		hm.put("lsId", departmentTable.getLsId());
		hm.put("bmMc", departmentTable.getBmMc());
		if(0 < departmentTableDao.update(hm))
			
			return true;
		else
		
			return false;
	}
	
	@Override
	public BeanDepartmentTable findByLsId(Integer lsId) throws Exception {
		
		if(null == lsId || 0 == lsId)
			
			return null;
		HashMap<String, Object> hm = new HashMap<String, Object>();
		hm.put("lsId", lsId);
		List<BeanDepartmentTable> list = find(hm);
		if(null == list || 0 == list.size())
			
			return null;
		return list.get(0);
	}

	@Override
	public BeanDepartmentTable findByBmMc(String bmMc) throws Exception {

		if(StringTools.isEmpty(bmMc))
			
			return null;
		HashMap<String, Object> hm = new HashMap<String, Object>();
		hm.put("bmMc", bmMc);
		List<BeanDepartmentTable> list = find(hm);
		if(null == list || 0 == list.size())
			
			return null;
		return list.get(0);
	}
	
	@Override
	public List<BeanDepartmentTable> find(HashMap<String, Object> hm) throws Exception {

		return departmentTableDao.find(hm);
	}
}
